<?php

/*
|--------------------------------------------------------------------------
| Broadcast Channels授权频道
|--------------------------------------------------------------------------
|
| Here you may register all of the event broadcasting channels that your
| application supports. The given channel authorization callbacks are
| used to check if an authenticated user can listen to the channel.
|
*/

Broadcast::channel('App.User.{id}', function ($user, $id) {
    return (int) $user->id === (int) $id;
});

/**
 * channel方法接收两个参数：频道的名称以及返回true或false以表明用户是否被授权可以监听频道的回调。

所有授权回调都接收当前认证用户作为第一个参数以及任意额外通配符参数作为随后参数，在本例中，我们使用{orderId}占位符标识频道名称的ID部分是一个通配符。
 */
Broadcast::channel('order.{$orderId}', function ($user, $orderId) {
    return (int) $user->id === $orderId;
});